//
//  StrategyTableviewCell.m
//  NewNest
//
//  Created by 王阳阳 on 16/3/9.
//  Copyright © 2016年 www.lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "StrategyTableviewCell.h"
#import <UIImageView+WebCache.h>
@implementation StrategyTableviewCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //标题
        self.titleLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.titleLabel];
        //图片
        self.titleImg = [[UIImageView alloc] init];
        [self.contentView addSubview:_titleImg];
        //内容
        self.contentLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_contentLabel];
        //类型
        self.styleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_styleLabel];
        //喜欢
        self.likeLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_likeLabel];
        //喜欢图片
        self.likeImg = [[UIImageView alloc] init];
        [self.contentView addSubview:_likeImg];
        //评论
        self.commentLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_commentLabel];
        //评论图片
        self.commentImg = [[UIImageView alloc] init];
        [self.contentView addSubview:_commentImg];
    }
    return self;
}
#pragma mark - 重写setter方法
- (void)setModel:(StrategyModel *)model{
    _model = model;
    _titleLabel.text = model.title;//名字
    _contentLabel.text = model.content;//内容
    _likeLabel.text = model.likeCount.stringValue;//喜欢个数
    _likeImg.image = [UIImage imageNamed:@"huiaixin@2x"];//喜欢按钮
    _commentImg.image = [UIImage imageNamed:@"huicomment@2x"];//评论按钮
    _commentLabel.text = model.commentCount.stringValue;//评论个数
    _styleLabel.text = model.categoryName;
    NSString *urlStr = [NSString stringWithFormat:@"http://gooju.cn/simages/%@_0_9-.jpg",model.covorPhotoId];
    [_titleImg sd_setImageWithURL:[NSURL URLWithString:urlStr]placeholderImage:[UIImage imageNamed:@"fang"]];
    
}
- (void)layoutSubviews{
    [super layoutSubviews];
    //标题
    self.titleLabel.frame = CGRectMake(20, 5, self.contentView.frame.size.width - 40, self.contentView.frame.size.height / 4);
    //不限制行数
    self.titleLabel.numberOfLines = 0;
    //居中
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    //图片
    self.titleImg.frame = CGRectMake(20, _titleLabel.frame.size.height + 10, (self.contentView.frame.size.width - 50) / 3, self.contentView.frame.size.height / 1.9);
    self.titleImg.layer.cornerRadius = 5;
   self.titleImg.contentMode = UIViewContentModeScaleAspectFill;
   self.titleImg.clipsToBounds = YES;
    //内容
    self.contentLabel.frame = CGRectMake(_titleImg.frame.size.width + 30, _titleImg.frame.origin.y, (self.contentView.frame.size.width - 50) / 3 * 2, _titleImg.frame.size.height / 3 * 2);
    _contentLabel.font = [UIFont systemFontOfSize:12];
    _contentLabel.numberOfLines = 0;
    //风格
    self.styleLabel.frame = CGRectMake(self.contentView.frame.size.width / 3 * 2,  _titleImg.frame.origin.y + _titleImg.frame.size.height / 3 * 2 + 5, _contentLabel.frame.size.width / 2, _titleImg.frame.size.height / 3 - 5);
    _styleLabel.textAlignment = NSTextAlignmentCenter;
    _styleLabel.font = [UIFont systemFontOfSize:13];
    _styleLabel.numberOfLines = 0;
    _styleLabel.textColor = [UIColor grayColor];
    //喜欢
    self.likeImg.frame = CGRectMake(self.contentView.frame.size.width / 2, _styleLabel.frame.origin.y + _styleLabel.frame.size.height + 5, self.contentView.frame.size.height - _titleLabel.frame.size.height - _titleImg.frame.size.height - 30, self.contentView.frame.size.height - _titleLabel.frame.size.height - _titleImg.frame.size.height - 30);
    self.likeLabel.frame = CGRectMake(_likeImg.frame.origin.x + _likeImg.frame.size.width, _likeImg.frame.origin.y, self.contentView.frame.size.width / 4 - _likeImg.frame.size.width , _likeImg.frame.size.height);
    _likeLabel.font = [UIFont systemFontOfSize:13];
    _likeLabel.textAlignment = NSTextAlignmentCenter;
    //评论
    self.commentImg.frame = CGRectMake(_likeLabel.frame.size.width + _likeLabel.frame.origin.x + 10, _likeImg.frame.origin.y, _likeImg.frame.size.width, _likeImg.frame.size.height);
    self.commentLabel.frame = CGRectMake(_commentImg.frame.size.width +_commentImg.frame.origin.x + 10, _likeImg.frame.origin.y, _likeLabel.frame.size.width, _likeLabel.frame.size.height);
    _commentLabel.font = [UIFont systemFontOfSize:13];
    _commentLabel.textAlignment = NSTextAlignmentCenter;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
